<template>
  <div class="exAminationEcharts">
    <div id="exAminationEcharts" style="width: 100%;"></div>
  </div>

</template>

<script>

  export default {
    props: ["perHourData", "perHour", "echartsNames","titleEcharts"],
    data(){
      return {
        seriesDispose: [],
        companyColor:this.$store.state.companyInfos,
        colors:[],
      }
    },
    mounted(){
      document.querySelector(".exAminationEcharts").style.height=document.querySelector(".examinationResultsWrap").clientHeight-390+"px"
      this.initData()
      //自适应
      window.addEventListener("resize", () => {
        this.myChart.resize();
      });
    },
    methods: {

      disposeData(){
        //处理颜色
        let arr =[]
        this.echartsNames.forEach(item=>{
          this.companyColor.forEach((item2) => {
            if(item==item2.enterpriseName){
              arr.unshift(item2.color)
              return true;
            }
          })
        })
        if(this.echartsNames.length==1){
          this.colors=["#33cc66"]
        }else {
          this.colors = arr.splice(0, this.echartsNames.length).reverse()
        }
        this.echartsNames.forEach((item, key) => {
          this.seriesDispose.unshift({
            name: item,
            type: 'line',
            data: this.perHourData[key],
            markPoint: {
              data: [
                {type: 'max', name: '最大值'},
                {type: 'min', name: '最小值'}
              ]
            },
          },)
        })
        this.seriesDispose = this.seriesDispose.splice(0, this.echartsNames.length).reverse()
      },
      initData(){
        this.disposeData()
        if (this.myChart != null && this.myChart != "" && this.myChart != undefined) {
          this.myChart.dispose();

        }

        this.myChart = this.echarts.init(document.getElementById('exAminationEcharts'))
        const colors = ['#FF4E17','#FED239',"green","#9f52d4","blue"]
        const option = {
          color: colors,
          title: {
            text: this.titleEcharts[0],
            subtext: '',
            x: 'center',
            textStyle: {
              fontSize: 15,
              fontWeight: 'bolder',
              color: '#3975FE'          // 主标题文字颜色
            },
          },
          /* toolbox: {
           show: true,
           x: 'right',                // 水平安放位置，默认为全图右对齐，可选为：
           // 'center' ¦ 'left' ¦ 'right'
           feature: {
           dataZoom: {
           yAxisIndex: 'none'
           },
           dataView: {readOnly: false},
           magicType: {type: ['line', 'bar']},
           restore: {},
           }
           },*/
          tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
              type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
          },
          legend: {
//            orient : 'vertical',
            x: 'right',
//            y: 'bottom',
            data: this.echartsNames,
            textStyle: {
              fontSize: 12,
              color: 'black'          // 主标题文字颜色
            },
          },
          grid: {
            left: '2%',
            right: '2%',
            bottom: '2%',
            top: '20%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: this.perHour,
              axisTick: {
                alignWithLabel: true
              },
              textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                color: 'black'
              },
              axisLine: {
                lineStyle: {
                  color: 'black',
                }
              }
            }
          ],
          yAxis: [
            {
              type: 'value',
              name:  this.titleEcharts[1],
              min: 0,
              textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                color: 'black'
              },
              axisLine: {
                lineStyle: {
                  color: 'black'
                }
              }
            }
          ],
          series: this.seriesDispose
        };
        this.myChart.setOption(option);
      }
    },
    watch: {
      perHourData(){
        this.initData()
      },
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .exAminationEcharts
    width: 100%
    height 100%
    margin 0 auto
    border-radius 15px
    padding-bottom 10px
    display: flex
    justify-content: center
    color black !important
</style>
